package com.bz.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bz.common.PageInfo;
import com.bz.common.PageUtil;
import com.bz.entity.ContactsCustomerEntity;
import com.bz.service.IContactsCustomerService;

@RestController
@RequestMapping(value = "/admin/contacts-customer")
public class ContactsCustomerController {

    @Autowired
    private IContactsCustomerService contactsCustomerService;

    @RequestMapping(value = "/list")
    public PageInfo list(@RequestParam(required = false) String name,
                         @RequestParam(required = false) String email,
                         @RequestParam(required = false) String lable,
                         @RequestParam(required = false) Long pageNo) {

        PageInfo page = PageUtil.getPageInfo(pageNo, PageUtil.pageSize);
        LambdaQueryWrapper<ContactsCustomerEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(name)) {
            queryWrapper.like(ContactsCustomerEntity::getName, name);
        }
        if (StringUtils.isNotEmpty(email)) {
            queryWrapper.like(ContactsCustomerEntity::getEmail, email);
        }
        if (StringUtils.isNotEmpty(lable)) {
            queryWrapper.like(ContactsCustomerEntity::getLable, lable);
        }
        return contactsCustomerService.list(page, queryWrapper);
    }
}
